package java_thinking.unit_17._17_9_10;

import java_thinking.unit_17._17_2_6.Countries;

import java.util.HashMap;
import java.util.Map;

import static java_thinking.net.mindview.util.Print.print;

/**
 * @Desc:   测试HashMap的查找速度
 * @author: cww
 * @DateTime: 2019-04-21 15:49
 */

public class E38_HashMapLoadFactor {
    public static void testGet(Map<String,String> fillMap,int n) {
        for (int tc = 0; tc < 100000; tc++) {
            for (int i = 0; i < Countries.DATA.length; i++) {
                String key = Countries.DATA[i][0];
                fillMap.get(key);
            }
        }
    }

    public static void main(String[] args) {
        HashMap<String,String> map1 = new HashMap<>();
        map1.putAll(Countries.capitals(11));
        HashMap<String,String> map2 = new HashMap<>(32);
        map2.putAll(map1);
        long t1 = System.currentTimeMillis();
        testGet(map1,11);
        long t2 = System.currentTimeMillis();
        print("map1 : " + (t2 - t1));
        t1 = System.currentTimeMillis();
        testGet(map2, 11);
        t2 = System.currentTimeMillis();
        print("map2 : " + (t2 - t1));
    }
}
